{extend name="$base" /}
{block name="resources"}
 <script type="text/javascript" src="__STATIC__/My97DatePicker/WdatePicker.js"></script> 
<style>
.panel-table{background-color:#FFF;}
.panel-table .btn_offline_pay{background: #FF8400;}
.panel-table .product-img{float:left;}
.panel-table .product-infor{float:left;margin-left: 10px;width:60%;}
.panel-table {border:1px solid #E3E3E3;}
.panel-table tbody td {border-right: 1px solid #E3E3E3;}
.panel-table .title-tr td input[type="checkbox"]{margin:0 0 0 7px;}
.panel-table .title-tr td span{margin-left:10px;}
</style>
{/block}
{block name="right_tab"}{/block}
{block name="main"}
<table class="mytable">
	<tr>
		<th style="line-height:33px;" class="default-condition">
			<input id="userName" class="input-common middle" type="text" value="" placeholder="请输入买家名称">
			<button onclick="searchData()" value="搜索" class="btn-common" >搜索</button>
			<button onclick="openSeniorSearch('.default-condition')" value="搜索" class="btn-common" >高级搜索</button>
		</th>		
	</tr>
</table>

<!-- 高级搜索 -->
<div class="nui-condition">
	<div class="c-item-column">
		<label>买家名称：</label>
		<input id="userName" class="input-common middle" type="text" value="" placeholder="请输入买家名称">
	</div>
	<div class="c-item-column">
		<label>订单编号：</label>
		<input id="orderNo" class="input-common middle" type="text" value="" placeholder="请输入订单编号">
	</div>

	<div class="c-item-column">
		<label>订单状态：</label>
		<select id="order_status" class="select-common middle">
			<option value="">全部</option>
			<option value=0>待付款</option>
			<option value="1">待发货</option>
			<option value="2">待收货</option>
			<option value="3">已收货</option>
			<option value="4">交易成功</option>
			<option value="5">已关闭</option>
			<option value=-1>退款中</option>
			<option value=-2>已退款</option>
		</select>
	</div>
	<br />
	<div class="c-item-column">
		<label>下单时间：</label>
		<input type="text" id="startDate" class="input-common middle" placeholder="请选择开始日期" onclick="WdatePicker()" />
		&nbsp;-&nbsp;
		<input type="text" id="endDate" placeholder="请选择结束日期" class="input-common middle" onclick="WdatePicker()" />
	</div>
	<br />

	<div class="c-operation">
		<button onclick="searchData()"  value="搜索" class="btn-common" >搜索</button>
		<a href="javascript:clearCondition();">清空筛选条件</a>
	</div>
	<a href="javascript:retractSeniorSearch();" class="retract">收起↑</a>
</div>

<div class="mod-table">
	<div class="mod-table-head">
		<div class="con style0list">
			<table class="table-class">
				<colgroup>
					<col style="width: 20%;">
					<col style="width: 15%;">
					<col style="width: 10%;">
					<col style="width: 10%;">
					<col style="width: 11%;">
					<col style="width: 17%;">
					<col style="width: 17%;">

				</colgroup>
				<thead>
					<tr>
						<th>订单号</th>
						<th>订单金额</th>
						<th>订单状态</th>
						<th>佣金</th>
						<th>买家</th>
						<th>创建时间</th>
						<th>完成时间</th>
					</tr>
				</thead>
				<colgroup>
					<col style="width: 20%;">
					<col style="width: 15%;">
					<col style="width: 10%;">
					<col style="width: 10%;">
					<col style="width: 11%;">
					<col style="width: 17%;">
					<col style="width: 17%;">
				</colgroup>
				<tbody id="tbody"></tbody>
			</table>
		</div>
	</div>
</div>
{/block}
{block name="script"} 
{include file="admin/openDialog" /}
<script type="text/javascript">
	//查询
	function searchData(){
		$(".more-search-container").slideUp();
		LoadingInfo(1);
	}
	//加载数据
	function LoadingInfo(pageIndex) {
		var start_date = $("#startDate").val();
		var end_date = $("#endDate").val();
		var user_name = $("#userName").val();
		var order_no = $("#orderNo").val();
		var order_status = $("#order_status").val();
		$.ajax({
			type : "post",
			url : "{:__URL('__URL__/nsfx/ADMIN_MODULE/Commission/commissionDistributionList')}",
			data : {
				"pageIndex" : pageIndex, "start_date" : start_date, "end_date" : end_date, "user_name":user_name, "order_no":order_no, "order_status" : order_status
			},
			success : function(data) {
				//alert(JSON.stringify(data));
				$("#page_count").val(data["page_count"]);
				$("#pageNumber a").remove();
				var html = '';
				if (data["data"].length > 0) {
					for (var i = 0; i < data["data"].length; i++) {

						html += '<tr align="center" data-show ="1" style="cursor:pointer;" onclick=showOrHideAccordion("accordiondata'+i+'",this);>';
						html += '<td>' + data["data"][i]["order_no"] + '</td>';
						html += '<td>' + data["data"][i]["order_money"] + '</td>';
						html += '<td>' + data["data"][i]["status_name"] + '</td>';
						html += '<td>' + data["data"][i]["commission_money"] + '</td>';
						html += '<td>' + data["data"][i]["user_name"] + '</td>';
						html += '<td>' + timeStampTurnTime(data["data"][i]["create_time"]) + '</td>';
						html += '<td>' + timeStampTurnTime(data["data"][i]["finish_time"]) + '</td>';
						html += '</tr>';
						html +='<tr class="collapse" style="display:none;" id="accordiondata'+i+'">';
						html +='<td colspan="7" style="padding:10px;background-color:#E0E0E0;" >';
						html +='<table class="panel-table table-class" ><colgroup>';
						html +='<col style="width: 35%;">';
						html +='<col style="width: 15%;">';
						html +='<col style="width: 10%;">';
						html +='<col style="width: 10%;">';
						html +='<col style="width: 12%;">';
						html +='<col style="width: 10%;">';
						html +='<col style="width: 8%;">';
						html +='</colgroup>';
						html +='<tbody>';

						//html +="<tr><td  colspan='8' style='border-left: 1px solid transparent;height:10px;padding:0px;border-right: 1px solid transparent;'></td></tr>";
						html += '<tr class="title-tr">';
						html += '<td>商品</td>';
						html += '<td>商品清单</td>';
						html += '<td>商品利润</td>';
						html += '<td>商品分销比率</td>';
						html += '<td>分销商佣金比例</td>';
						html += '<td>佣金金额</td>';
						html += '<td>收益人</td>';
						html += '</tr>';
						
						//循环订单项
						for(var j = 0; j < data["data"][i]["order_item_list"].length; j++){
							var commission_distribution_item = data["data"][i]["order_item_list"][j]["commission_distribution_list"];
							var row = 1;
							if(commission_distribution_item.length >0){
								row = commission_distribution_item.length+1
							}
							html += '<tr class="no-rightborder"><td style="border-right:0;" rowspan="'+row+'">';
							html += '<div class="product-img"><img src="'+ __IMG(data['data'][i]['order_item_list'][j]['picture']['pic_cover_micro']) +'"/></div>';
							html += '<div class="product-infor">';
							html += '<a class="name" href="'+__URL('APP_MAIN/goods/detail?goods_id='+data["data"][i]["order_item_list"][j]["goods_id"])+'" target="_blank">'+data["data"][i]["order_item_list"][j]["goods_name"]+'</a>';
							html += '<p class="specification"><span>'+data["data"][i]["order_item_list"][j]["sku_name"]+'</span></p></div>';
							html += '</div></td>';
							html += '<td style="border-left:0px solid #fff;border-right:1px solid #E3E3E3;" rowspan="'+row+'">';//商品信息与商品清单的分割线
							//html += '<div class="cell" style="display: inline-block;"><span>'+data["data"][i]["order_item_list"][t]["goods_name"]+'</span></div>';
							html += '<div class="cell" style="display: inline-block;"><span>'+data["data"][i]["order_item_list"][j]["price"]+'元</span></div>';
							html += '<div class="cell" style="display: inline-block;float:right">'+data["data"][i]["order_item_list"][j]["num"]+'件</div>';
							if(data["data"][i]["order_item_list"][j]['adjust_money'] != 0){
								html += '<div class="cell" style="display: inline-block;"><span>(调价：'+data["data"][i]["order_item_list"][j]["adjust_money"]+'元)</span></div>';
							}
// 							if((data["data"][i]["order_item_list"][j]['refund_status'] != 0) && (data["data"][i]["order_item_list"][j]['refund_operation'] != ''))
							if(commission_distribution_item.length >0){
								for(t = 0; t< commission_distribution_item.length;t++){
									html +='</tr>';
									html +='<tr class="no-rightborder">';
									html +='<td>'+parseFloat(commission_distribution_item[t]["goods_return"]).toFixed(2)+'</td>';
									html +='<td>'+parseFloat(commission_distribution_item[t]["goods_commission_rate"]).toFixed(2)+'%</td>';
									html +='<td>'+parseFloat(commission_distribution_item[t]["commission_rate"]).toFixed(2)+'%</td>';
									html +='<td>'+parseFloat(commission_distribution_item[t]["commission_money"]).toFixed(2)+'</td>';
									html +='<td>'+commission_distribution_item[t]["promoter_shop_name"]+'('+'姓名:'+commission_distribution_item[t]["realname"]+'<br/>'+'编号:'+commission_distribution_item[t]["promoter_no"]+')'+'</td>';
								}
							}else{
								html +='<td>0.00</td>';
								html +='<td>0.00%</td>';
								html +='<td>0.00%</td>';
								html +='<td>0.00</td>';
								html +='<td></td>';
							}
							html += '</tr>';
						}
						html +='</tbody></table>';
						html +='</td>';
						html +='</tr>'
					}
				} else {
					html += '<tr align="center"><td colspan="7">暂无符合条件的数据记录</td></tr>';
				}
				
				$(".style0list tbody").html(html);
				var totalpage = $("#page_count").val();
				if (totalpage == 1) {
					changeClass("all");
				}
				initPageData(data["page_count"],data['data'].length,data['total_count']);
				var $html = pagenumShow(jumpNumber,totalpage,{$pageshow});
				$("#pageNumber").append($html);
			}
		});
	}
	
	//全选
	function CheckAll(event){
		var checked = event.checked;
		$(".style0list tbody input[type = 'checkbox']").prop("checked",checked);
	}
	
	function showOrHideAccordion(accordion_id,event){
		if($(event).data("show") == 1){
			$(event).data("show",0);
			$('#'+accordion_id).show();
		}else{
			$(event).data("show",1);
			$('#'+accordion_id).hide();
		}
		
	}
	
	// 点击显示更多搜索
	$(".more-search").on("click", function(e){
		$(".more-search-container").slideToggle();
		$(document).one("click", function(){
	        $(".more-search-container").slideUp();
	    });
	    e.stopPropagation();
	});

	$(".more-search-container").on("click", function(e){
	    e.stopPropagation();
	});
</script>
{/block}